import { createStore, applyMiddleware, compose } from 'redux';
import createRootReducer from '../reducers'
import ReduxThunk from 'redux-thunk'
import { routerMiddleware } from 'connected-react-router'
import { createHashHistory } from 'history'
export const history = createHashHistory()
import { composeWithDevTools } from 'redux-devtools-extension'
/**
 * 配置函数
 * @return {[type]} 返回创建的store
 */
export default function configureStore() {

    const store = createStore(
        createRootReducer(history), // root reducer with router state
        compose(
            applyMiddleware(
                routerMiddleware(history), // for dispatching history actions
                ReduxThunk
            ),
            composeWithDevTools()
        )
    )

    if (module.hot) {
        module.hot.accept('../reducers/index.js', ()=>{
            const nextRootReducer = require('../reducers/index.js').default;
            store.replaceReducer(nextRootReducer)
        });
    }

    return store
}
